<?php
class Application_Model_IndustryCompany
{
	protected $_dbTable;
	public $_mIndustryId;
	public $_mCompanyId;

	public function getIndustryId(){
		return $this->_mIndustryId;
	}
	public function setIndustryId($value){
		$this->_mIndustryId = $value;
		return $this;
	}
	public function getCompanyId(){
		return $this->_mCompanyId;
	}
	public function setCompanyId($value){
		$this->_mCompanyId = $value;
		return $this;
	}


	public function setDbTable($dbTable){
		if (is_string($dbTable))
			$dbTable = new $dbTable();
		if (!$dbTable instanceof Zend_Db_Table_Abstract)
			throw new Exception('Invalid table data gateway provided');
		$this->_dbTable = $dbTable;
		return $this;
	}
	public function getDbTable(){
		if (null === $this->_dbTable)
			$this->setDbTable('Application_Model_DbTable_IndustryCompany');
		return $this->_dbTable;
	}
	public function save(Application_Model_IndustryCompany $old = null){
		$item = $this;
		$data = array();
		if(isset($item->_mIndustryId)) $data['industry_id'] = $item->_mIndustryId;
		if(isset($item->_mCompanyId)) $data['company_id'] = $item->_mCompanyId;

		if($old === null)
			$this->getDbTable()->insert($data);
		else{
			$key = array();
			$old->_mIndustryId === null ? $key[] = 'industry_id is NULL' : $key['industry_id = ?'] =  $old->_mIndustryId;
			$old->_mCompanyId === null ? $key[] = 'company_id is NULL' : $key['company_id = ?'] =  $old->_mCompanyId;

			$this->getDbTable()->update($data, $key);
		}
	}
	public function delete(){
		$item = $this;
		$old = $item;
		$key = array();
			$old->_mIndustryId === null ? $key[] = 'industry_id is NULL' : $key['industry_id = ?'] =  $old->_mIndustryId;
			$old->_mCompanyId === null ? $key[] = 'company_id is NULL' : $key['company_id = ?'] =  $old->_mCompanyId;

		$this->getDbTable()->delete($key);
	}
	public function fetchAll($where = null, $order = null, $count = null, $offset = null){
		$resultSet = $this->getDbTable()->fetchAll($where, $order, $count, $offset);
		$entries   = array();
		foreach ($resultSet as $row) {
			$item = new Application_Model_IndustryCompany();
			if(isset($row->industry_id))$item->_mIndustryId = $row->industry_id;
			if(isset($row->company_id))$item->_mCompanyId = $row->company_id;

			$entries[] = $item;
		}
		return $entries;
	}
}
